const White = 0xFFFFFFFF;

// Function hooking example that adds all created vehicles to
// an array then deletes them when the script unloads
local logEnable = true;
local vehicles = {};
//local createVehicle_Original = createVehicle;

local faggioID = [0,0,0,0,0,0,0,0];
local doorsBlocked = [0,0,0,0,0,0,0];
local carID = array(getPlayerSlots(),0);

local vehHealth;
local vehStatLock;
local vehicleid;
local vhealth;
local speed;

local plaleySit = array(getPlayerSlots(), 0);
local timerSit = array(getPlayerSlots(), 0);
local pWorkMoney = array(getPlayerSlots(),0);
local pState = array(getPlayerSlots(),0);

local checkpoint; // Strip Club checkpoint work
local checkPointsEnterHouseClassA = array(255,0);
local checkPointsExitFromHouseA = array(255,0);
local atmCheckpoint = array(255,0);

local checkpointMeryaWork;
local housesCount = 14;

local playerHouseID = array(255,0);
local houseCoordSpawnAX = [0,-1246.665649]; // 1 = AClass
local houseCoordSpawnAY = [0,1542.129028];
local houseCoordSpawnAZ = [0,26.068846];

// 14 входов
local houseAEnterX = [1323.542725,1362.298218,1365.198364,1323.706909,1365.292847,1415.137573,1417.144653
,1326.613037,1361.915894,1317.300049,1311.178345,1354.075073,1312.031372,1338.498657];
local houseAEnterY = [-846.844055,-862.864502,-833.527771,-802.010193,-790.344727,-831.280640,-788.958984
,-784.746338,-749.192139,-756.437012,-741.057556,-694.518860,-693.267700,-659.183533];
local houseAEnterZ = [8.864146,8.420816,9.025394,8.178944,9.025602,9.062482,8.138374
,8.666511,9.416680,8.590585,8.482475,8.678661,8.890264,8.649170];

local houseAExitPosX = [0,1324.826172,1361.333374,1363.918335,1325.320801,1363.627808,1414.602661,1417.075195
,1328.610718,1359.856445,1319.161011,1313.157959,1352.700684,1313.832642,1336.950195];
local houseAExitPosY = [0,-846.789368,-862.889832,-833.599548,-801.989319,-790.448181,-829.838867,-790.420959
,-784.753418,-749.685730,-756.306702,-741.195618,-694.510681,-693.194580,-660.376465];
local houseAExitPosZ = [0,8.872727,8.317761,9.025394,8.178944,9.025603,9.062482,8.216504
,8.321627,9.416671,8.242762,8.296366,8.678661,8.504115,8.696633];

local vehiclePosClassAX = [0,1323.577637,1361.848511,1372.475830,1305.496338,1367.418701,1401.757202,1401.279175
,1303.677612,1372.936523,1298.956909,1291.272949,1362.406128,1292.379517,1353.344360];
local vehiclePosClassAY = [0,-819.210449,-868.231018,-846.321777,-790.970093,-781.174194,-836.141052,-775.648376
,-770.700378,-764.975952,-747.879211,-726.679199,-686.501892,-685.183655,-672.481445];
local vehiclePosClassAZ = [0,7.892056,7.971440,8.011414,7.847532,8.170899,7.904150,7.476980
,7.892533,8.075301,7.899705,7.525479,7.259995,8.248116,7.367224];
local vehicleRotClassAX = [0,0.334595,359.771240,0.786255,0.430420,0.710449,0.680603,1.536011
,359.852051,357.128174,0.006958,359.398193,358.100220,359.946655,356.590515];
local vehicleRotClassAY = [0,3.114136,359.999146,359.676208,359.537842,359.322388,357.861084,359.989746
,359.375000,0.589844,359.434937,3.214722,359.798157,358.667297,1.963989];
local vehicleRotClassAZ = [0,270.790405,271.509338,89.769714,88.902588,96.313293,15.821899,179.711548
,87.835815,280.926147,88.888611,88.407959,269.295654,90.297974,268.362793];

local playerVehicleHouse = array(260,0);

local houseNumber = array(2000,0);
local selledHouse = array(2000,0);
local houseClass = array(2000,0);

local houseInfoPName = array(2000,0);
local houseInfoSelled = array(2000,0);

local moneyToCheck = 0;
local pHealthToCheck = 0;

local stateEng;
local engineState;

function isNumbers(str);

function getDist(pos1, pos2)
{
return sqrt((((pos1[0] - pos2[0])*(pos1[0] - pos2[0])) + ((pos1[1] - pos2[1])*(pos1[1] - pos2[1])) + ((pos1[2] - pos2[2])*(pos1[2] - pos2[2]))));
}

function onConsoleInput(cmd)
{
	local cmd = split(cmd, " ");
	
	if(cmd[0] == "res")
	{
		log(format("The Server will restart in %d seconds..",cmd[1].tointeger()));
		return true;
	}
	else if(cmd[0] == "getpm")
	{
		foreach(i, playername in getPlayers())
		{
			if(isPlayerConnected(i))
			{
			log("PlayerName: "+playername+" Money: "+getPlayerMoney(i));
			}
		}
		return true;
	}
	
	return true;
}
addEvent("consoleInput",onConsoleInput);


function loadHouseInfo(houseCount)
{

if(fileExists("houseConfig.ini")==false)
{
local ini = EasyINI("houseConfig.ini");
for(local n = 0; n <= houseCount; n++)
{
ini.setKey("houseInfoPName",n.tostring(),"Sale");
ini.setKey("houseInfoSelled",n.tostring(),1);
}
ini.saveData();
}

if(fileExists("houseConfig.ini")==false){return log("Error: can't create houseConfig file.");}

local ini = EasyINI("houseConfig.ini");
	for(local h = 1/*0 был, если чо*/; h <= houseCount; h++) // h = houseNumber
	{
		houseInfoPName[h] = ini.getKey("houseInfoPName",h.tostring()).tostring();
		houseInfoSelled[h] = ini.getKey("houseInfoSelled",h.tostring()).tointeger();
		selledHouse[h] = houseInfoSelled[h]; // Продан дом или нет?
		loging("House stateID:"+h+" Houser name: "+houseInfoPName[h]+" House Selled: "+selledHouse[h]+" Cmp: "+houseInfoSelled[h]);
	}
ini.saveData();

return true;
}

function saveHouseInfo(playerid)
{
local ini = EasyINI("houseConfig.ini");

	ini.setKey("houseInfoPName",playerHouseID[playerid].tostring(),getPlayerName(playerid).tostring());
	ini.setKey("houseInfoSelled",playerHouseID[playerid].tostring(),selledHouse[playerHouseID[playerid]].tointeger());
ini.saveData();
return 1;
}

local registredUser = array(getPlayerSlots(),0);
// Players state
local health = array(getPlayerSlots(),0);
local pMoney = array(getPlayerSlots(),0);
local pVehicleHealth = array(260,0);
local vehicleFuel = array(260,0);
local classH = array(getPlayerSlots(),0);
local pSkin = array(345,0);
local pVehicleLocked = array(getPlayerSlots(),0);
local pWork = array(getPlayerSlots(),0);

local pGender = array(getPlayerSlots(),0);
local skinsHobosMale = [122,126,266,267];

// Real Time
local currTime = date();

//setMinuteDuration(60000);
function payDay();

function timeDuration()
{
currTime = date();
setTime(currTime.hour, currTime.min);
setDayOfWeek(currTime.wday);

	if(currTime.min == 0)
	{
	// PayDay
	payDay();
	}
	
return 1;
}

local timerSpeed = array(getPlayerSlots(),0);

function anim(playerid)
{
forcePlayerPlayAnimation(playerid,"missambtv","sit_loop");
}

function timeView(playerid)
{
setPlayerUseMobilePhone(playerid,false);
}

local blipsHouses = array(2000,0);

function createVehicleEx(model, x, y, z, rx, ry, rz, c1, c2, c3, c4, respawn_delay = -1)
{
	local vehicleId = createVehicle(model, x, y, z, rx, ry, rz, c1, c2, c3, c4, respawn_delay);

	if(vehicleId != INVALID_VEHICLE_ID)
	{
		loging("Created a vehicle with id " + vehicleId + " (Model " + model + " (" + getVehicleName(model) + "))");
		vehicles[vehicles.len()] <- vehicleId;
		vehicleFuel[vehicleId] = 120.0;
		setVehicleDimension(vehicleId, 0);
	}

	return vehicleId;
}

function loging(str)
{
if(logEnable)
{
return log(str);
}
return false;
}

function random(min, max)
{
	srand(time());
	return (rand() % max + min);
}

local prevWeather;
local repeat = 0;

function onWeatherChange()
{

if(random(1,60) > 55 && prevWeather != 6 && prevWeather != 5 && prevWeather != 4 && prevWeather != 8)
{
setWeather(6); // Время грозы
}

prevWeather = getWeather();

if(prevWeather != 6 && prevWeather != 5 && prevWeather != 4 && prevWeather != 8) // если погода не начало дождя то
{
	if(currTime.hour >= 6 && currTime.min >= 0 && currTime.hour <= 7 && currTime.min <= 59) // 06-08
	{
		setWeather(7); // Туман
	}
	else if(currTime.hour >= 8 && currTime.min >= 0 && currTime.hour <= 15 && currTime.min <= 59) // 08-16
	{
		setWeather(3); // немного притуманено
	}
	else if(currTime.hour >= 16 && currTime.min >= 0 && currTime.hour <= 19 && currTime.min <= 59) // 16-20
	{
		setWeather(9); // Ясно
	}
	else if(currTime.hour >= 20 && currTime.min >= 0 && currTime.hour <= 23 && currTime.min <= 59) // 20-00
	{
		setWeather(1); // Вечер
	}
	else if(currTime.hour >= 0 && currTime.min >= 0 && currTime.hour <= 1 && currTime.min <= 59) // 00-02
	{
		setWeather(10); // Вечер
	}
	else if(currTime.hour >= 2 && currTime.min >= 0 && currTime.hour <= 3 && currTime.min <= 59) // 02-04
	{
		setWeather(2);
	}
	else if(currTime.hour >= 4 && currTime.min >= 0 && currTime.hour <= 5 && currTime.min <= 59) // 04-06
	{
		setWeather(3);
	}
}
else
{
		if(prevWeather == 6 && repeat == 0) // Мелкий дождь
		{
		setWeather(5); // Усиленный дождь
		loging("5");
		}
		else if(prevWeather == 5 && repeat == 0) // Усиленный дождь
		{
		setWeather(8); // Гроза
		loging("8");
		}
		else if(prevWeather == 8 && repeat == 0)
		{
		setWeather(5); // Усиленный дождь
		repeat = 1;
		loging("5+rep");
		}
		else if(prevWeather == 5 && repeat == 1)
		{
		setWeather(4); // после дождя
		repeat = 0;
		loging("4-rep");
		}
		else if(prevWeather == 4 && repeat == 0)
		{
		setWeather(3); // после дождя 2
		loging("3");
		}
}

loging("PrevWeath: "+prevWeather+" Cur:"+getWeather());
}

function onScriptInit()
{
dofile("scripts/easyini.nut");
dofile("scripts/dialog.nut");
timeDuration();
timer(timeDuration,60000,-1);
saveBank();
timer(onWeatherChange,300000,-1); // 900000
onWeatherChange();

faggioID[0] = createVehicleEx(106, 2273.199951, 474.564575, 5.441020, 0.139404, 0.008667, 0.983887, 1, 1, 1, 1); // faggio1
faggioID[1] = createVehicleEx(106, 2269.620117, 474.365570, 5.441749, 0.250122, 359.996704, 0.611816, 1, 1, 1, 1); // faggio2
faggioID[2] = createVehicleEx(106, 2266.500488, 474.090027, 5.441935, 0.108521, 0.001465, 358.512329, 1, 1, 1, 1); // faggio3
faggioID[3] = createVehicleEx(106, 2263.421143, 473.852448, 5.441806, 0.192749, 0.015869, 0.997986, 1, 1, 1, 1); // faggio4
faggioID[4] = createVehicleEx(106, 2260.073242, 473.873199, 5.447759, 359.757080, 359.997070, 0.312866, 1, 1, 1, 1); // faggio5
faggioID[5] = createVehicleEx(106, 2256.797363, 474.519989, 5.439699, 359.933716, 0.007141, 358.623657, 1, 1, 1, 1); // faggio6
faggioID[6] = createVehicleEx(106, 2253.568848, 474.075134, 5.439699, 0.045776, 359.994019, 359.802063, 1, 1, 1, 1); // faggio7
faggioID[7] = createVehicleEx(106, 2250.362793, 473.840210, 5.442590, 0.227783, 0.003662, 359.926514, 1, 1, 1, 1); // faggio8


// Blocked Doors creates
doorsBlocked[0] = createObject(1407305516, 891.800, -501.400, 19.6000, 0.0, 0.0, 0.0); // First House Niko
doorsBlocked[1] = createObject(1407305516, 602.25, 1404.8, 17.5, 0.0, 0.0, 0.0); //
doorsBlocked[2] = createObject(1407305516, -1247.3, 1539.865234, 26.308846, 0.0, 0.0, 0.0); // HouseDoor Class A
doorsBlocked[3] = createObject(1407305516, -1247.3, 1559.722412, 26.308846, 0.0, 0.0, 0.0); // HouseDoor Class A

log(_version_);
local config = getConfig();
log("Port = " + config["port"]);
log(SCRIPT_NAME + " sucessfully loaded");

loadHouseInfo(housesCount); // 14 домов

	for(local n = 0; n < housesCount; n++)
	{
		blipsHouses[n] = createBlip(29, houseAEnterX[n], houseAEnterY[n], houseAEnterZ[n], true); // Create Home Blip
		if(houseInfoSelled[n+1] == 1)
		{
			setBlipColor(blipsHouses[n],0x00FF00FF,-1); // Имеется владелец
			setBlipName(blipsHouses[n], houseInfoPName[n+1]);
			loging("HouseS: "+houseInfoSelled[n+1]+" Name: "+houseInfoPName[n+1]+" HN: "+n+" BlipID: "+blipsHouses[n]);
		}
		else
		{
			setBlipColor(blipsHouses[n],0x0000FFFF,-1); // Продается
			setBlipName(blipsHouses[n], houseInfoPName[n+1]);
			loging("HouseS: "+houseInfoSelled[n+1]+" Name: "+houseInfoPName[n+1]+" HN: "+n+" BlipID: "+blipsHouses[n]);
		}
	}
log("Houses loaded: "+housesCount);

// Weapon Shops
createBlip(59,1055.767212, 86.800735, 33.467216,true); // Weapon Shop

// Clothe Shops
createBlip(50,894.105713,-442.889771,15.865152,true); // Clothes Shop

// Bar's
createBlip(47,926.468018, -490.177338, 15.333056,true); // Vlad Bar

// Burgers Shot
createBlip(21,957.429321, -294.975159, 19.583292,true); // Burger Shot
createBlip(21,884.295898, -479.751312, 15.888259,true); // Burger Shot
createBlip(21,1655.073608, 226.018326, 24.987631,true); // Burger Shot

// Porn
createBlip(55,781.453491, -542.429138, 9.403580,true); // Porno Shop

// Gas stations
createBlip(36,1128.840088, -358.378448, 18.510990,true); // Gas Station
createBlip(36,1123.822388, 328.865997, 29.470770,true); // Gas Station
createBlip(36,1453.837158, 1711.662720, 16.324202,true); // Gas Station

// ATM's
createBlip(85,2297.706787, 453.744263, 6.085058,true); // ATM Voczal
createBlip(85,937.333618, -554.688965, 14.127687,true); //

// Strip Clubs
createBlip(66,1202.940063, 1716.783569, 16.666100,true); // Strip Club

// Meriya
createBlip(25,79.697784, -713.444458, 4.958698,true);

// Internet
createBlip(24,976.070007, -169.464630, 23.974861,true);


for(local n = 0; n < 7; n++)
{
setObjectDimension(doorsBlocked[n],255); // Loked doors virtualWorld
}
	
timer(onHealthCalc, 60000, -1);
timer(onAnticheatCheck,2000,-1);
log("Anti-Cheat cheker started");

return 1;
}
addEvent("scriptInit", onScriptInit);

function isFaggio(veh)
{
if(veh >= faggioID[0] && veh <= faggioID[7])
{
return 1;
}

return 0;
}

function addCheckpoint()
{
    checkpoint = createCheckpoint(6, 1176.281250, 1682.430176, 17.726965, 1176.281250, 1682.430176, 17.726965, 0.2);
	checkPointsExitFromHouseA[0] = createCheckpoint(6, -1246.528320, 1540.182861, 26.068867, -1246.528320, 1540.182861, 26.068867, 0.1);	
	for(local n = 0; n < housesCount; n++)
	{
	checkPointsEnterHouseClassA[n] = createCheckpoint(6, houseAEnterX[n],houseAEnterY[n],houseAEnterZ[n], houseAEnterX[n],houseAEnterY[n],houseAEnterZ[n]+20, 0.1);
	setCheckpointDimension(checkPointsEnterHouseClassA[n], 0); // 0 = Global WorldID
	houseNumber[checkPointsEnterHouseClassA[n]] = n+1;
	}
	// 95.701485, 851.824036, 45.050949 D
	// Чекпойнты нужно создавать всегда ниже предыдущих! иначе, это нарушит систему нумерации домов
	checkpointMeryaWork = createCheckpoint(2, 123.762352,-686.693665,14.771738, 123.762352,-686.693665,14.771738, 0.1);
	
	atmCheckpoint[0] = createCheckpoint(2,937.333618, -554.688965, 14.127687, 937.333618, -554.688965, 14.127687, 0.1);
	atmCheckpoint[1] = createCheckpoint(2,2297.706787, 453.744263, 6.085058, 2297.706787, 453.744263, 6.085058, 0.1);
	
	setCheckpointDimension(checkPointsExitFromHouseA[0],255); // 255 all worlds
	setCheckpointDimension(checkpoint, 0);
	setCheckpointDimension(checkpointMeryaWork,0);
}
addEvent("scriptInit", addCheckpoint);

function onPlayerWorkTimer(playerid)
{
	if(pWork[playerid] == 1) // Стриптизерша
	{
			pWorkMoney[playerid] = 100; // Деньги для выдачи на счет
			saveBank(playerid,pWorkMoney[playerid]);
			pState[playerid] = 0; // Освободился
	}
}

function onPlayerEnterCheckpoint(playerid, checkpointId)
{
if(!isPlayerInAnyVehicle(playerid))
{
		if(checkpointId == checkpoint && pState[playerid] != 1) // Test Strip
		{
			if(pWork[playerid] == 1) // Стриптизерша
			{
			setPlayerCoordinates(playerid,1176.281250, 1682.330176/*1682.430176*/, 17.726965);
			setPlayerHeading(playerid,45.0);
			forcePlayerPlayAnimation(playerid,"missstripclublo","pole_dance_a");
			timer(onPlayerWorkTimer,80000,1,playerid);
			pState[playerid] = 1; // Занят работой
			}
		return 1;
		}
		else if(checkpointId >= checkPointsEnterHouseClassA[0] && checkpointId <= checkPointsEnterHouseClassA[13]) // +1
		{
		sendPlayerMessage(playerid,"HouseNumber: "+houseNumber[checkpointId]+" HousePID: "+playerHouseID[playerid]);
		loging("Log: "+houseNumber[checkpointId]);
			if(houseNumber[checkpointId] == playerHouseID[playerid] && selledHouse[houseNumber[checkpointId]] != 1) // Если это наш дом
			{
				setPlayerDimension(playerid,houseNumber[checkpointId]);
				setPlayerCoordinates(playerid, houseCoordSpawnAX[1], houseCoordSpawnAY[1], houseCoordSpawnAZ[1]);	
				//  891.390076, -499.447021, 19.420979 D
				displayPlayerText(playerid, 0.3, 0.8, "~y~"+getPlayerName(playerid)+" Home", 5000);
				return 1;
			}
			else if(playerHouseID[playerid] == 0 && selledHouse[houseNumber[checkpointId]] == 1)
			{
				// Покупка дома
				setPlayerDimension(playerid,houseNumber[checkpointId]);
				setPlayerCoordinates(playerid, houseCoordSpawnAX[1], houseCoordSpawnAY[1], houseCoordSpawnAZ[1]);
				sendPlayerMessage(playerid,"Этот дом продается, введите [FF0000FF]/buyhouse [FAA460FF]чтобы купить. Стоимость [00FF00FF]2000000$",0xFAA460FF,true);
				return 1;
			}
			else if(selledHouse[houseNumber[checkpointId]] == 0 && houseNumber[checkpointId] != playerHouseID[playerid])
			{
				// В гостях у
				setPlayerDimension(playerid,houseNumber[checkpointId]);
				setPlayerCoordinates(playerid, houseCoordSpawnAX[1], houseCoordSpawnAY[1], houseCoordSpawnAZ[1]);	
				sendPlayerMessage(playerid,"Вы зашли в гости к [FAA460FF]"+houseInfoPName[houseNumber[checkpointId]],0xFFFFFFFF,true);
				return 1;
			}
			else
			{
			sendPlayerMessage(playerid,"У вас уже есть дом.",0xFF0000FF);
			return 1;
			}
			
		}
		else if(checkpointId == checkPointsExitFromHouseA[0])
		{
			local dimen = getPlayerDimension(playerid);
			setPlayerDimension(playerid, 0); // 0 = Global WorldID
			setPlayerCoordinates(playerid, houseAExitPosX[dimen], houseAExitPosY[dimen], houseAExitPosZ[dimen]);
			return 1;
		}
		else if(checkpointId == checkpointMeryaWork)
		{
			dialog.showPlayerDialog(playerid,4,2,"Приём на работу:","Танцовщица в стриптиз клуб");
			return 1;
		}
		else if(checkpointId >= atmCheckpoint[0] && checkpointId <= atmCheckpoint[1]) // Банкоматы
		{
			dialog.showPlayerDialog(playerid,1000,2,"Банковские услуги:","Посмотреть счет\nСнять деньги");
			return 1;
		}
	}
	
return 1;
}
addEvent("playerEnterCheckpoint", onPlayerEnterCheckpoint);

function onScriptExit()
{	
	for(local i = 0; i < vehicles.len(); i++)
	{
		deleteVehicle(vehicles[i]);
	}
	
	return 1;
}
addEvent("scriptExit", onScriptExit);

function onPlayerConnect(playerid, name)
{

	if(fileExists(getPlayerName(playerid)+".ini")==false)
	{
		registredUser[playerid] = 0;
	}
	else
	{
		registredUser[playerid] = 1;
	}

return 1;
}
addEvent("playerConnect", onPlayerConnect);

function onPlayerChangeState(playerid, oldstate, newstate)
{
	if(newstate == STATE_TYPE_INVEHICLE)
	{
	//timerSpeed[playerid] = timer(vStats,500,-1,playerid);
	return 1;
	}
	else if(newstate == STATE_TYPE_ONFOOT && oldstate == STATE_TYPE_INVEHICLE)
	{
		if(timerSpeed[playerid].isActive())
		{
		   timerSpeed[playerid].kill();
		   return 1;
		}
	}
	else if(newstate == STATE_TYPE_DISCONNECT && oldstate == STATE_TYPE_INVEHICLE)
	{
		if(timerSpeed[playerid].isActive())
		{
		   timerSpeed[playerid].kill();
		   loging("timerSpeed[playerid].kill();");
		   return 1;
		}
	}

return 1;
}
addEvent("playerChangeState", onPlayerChangeState);

function onPlayerJoin(playerid)
{
sendPlayerMessage(playerid, "Добро пожаловать на сервер RP!",0xFAA460FF);

if(registredUser[playerid] == 0)
{
sendPlayerMessage(playerid,"Вы не зарегестрированы, пожалуйста, пройдите регистрацию.",0xFAA460FF);
dialog.showPlayerDialog(playerid,0,1,"Регистрация, введите пароль:",""); // 0 = id диалога
}
else
{
sendPlayerMessage(playerid,"Этот аккаунт уже зарегистрирован, выполните вход.",0xFAA460FF);
dialog.showPlayerDialog(playerid,1,1,"Вход:","");
}

setPlayerSpawnLocation(playerid, 0.0, 0.0, 0.0, 0.0);

setPlayerDimension(playerid, 0);
}
addEvent("playerJoin", onPlayerJoin);

function onPlayerDisconnect(playerid, reason)
{
	local strreason = "Quit";
	
	if(registredUser[playerid] == 2) // 2 = если залогинился, 1 = если только получил коннект но зарегистрирован
	{
	
	local ini = EasyINI(getPlayerName(playerid)+".ini");
	if(getPlayerHealth(playerid) < 10)
	{health[playerid] = 50;}
	ini.setKey("stats","health",health[playerid]);
	ini.setKey("stats","money",pMoney[playerid]);

	if(playerVehicleHouse[playerHouseID[playerid]] != 300)
	{
	pVehicleHealth[playerid] = getVehicleHealth(playerVehicleHouse[playerHouseID[playerid]]);
	if(pVehicleHealth[playerid] < 150){pVehicleHealth[playerid] = 150;}else if(pVehicleHealth[playerid] > 1000){pVehicleHealth[playerid] = 1000;}
	ini.setKey("stats","vehicleHealth",pVehicleHealth[playerid]);
	if(vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]] > 120.0){vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]] = 120.0;}else if(vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]] < 0.0){vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]] = 0.0;}
	ini.setKey("stats","vehicleFuel",vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]].tofloat());
	vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]] = 0;
	}
	ini.saveData();
	
	health[playerid] = 0;
	pGender[playerid] = 1;
	pMoney[playerid] = 0;
	pSkin[playerid] = 0;
	pVehicleHealth[playerid] = 0;
	deleteVehicle(playerVehicleHouse[playerHouseID[playerid]]);
	playerVehicleHouse[playerHouseID[playerid]] = 0;
	playerHouseID[playerid] = 0;
	classH[playerid] = 0;
	pWork[playerid] = 0;
	carID[playerid] = 300;
	pState[playerid] = 0;
	pWorkMoney[playerid] = 0;
	
	registredUser[playerid] = 0;
	}
	
	if(plaleySit[playerid] == 1)
	{
		if(timerSit[playerid].isActive()) // Kill timer sit animation
		{
			timerSit[playerid].kill();
			plaleySit[playerid] = 0;
		}
	}
	
	if(reason == 1)
		strreason = "Timeout/Crash";

	deletePlayerBlip(playerid);
	return 1;
}
addEvent("playerDisconnect", onPlayerDisconnect);

function onSpawn(playerid)
{

	createPlayerBlip(playerid, 3);
	togglePlayerBlipShortRange(playerid,true);
	
	// Request here all animations, which you use
	// ATTENTION: It can take 1 up to 5 seconds to load the animation(s) successfully!
	requestPlayerAnimations(playerid,"amb@smoking_spliff");
	requestPlayerAnimations(playerid,"amb@taxi_wait_i_f_b");
	requestPlayerAnimations(playerid,"amb@taxi_hail_f");
	requestPlayerAnimations(playerid,"missttkill");
	requestPlayerAnimations(playerid,"missstripclublo");
	requestPlayerAnimations(playerid,"missambtv");
	requestPlayerAnimations(playerid,"amb@umbrella_f_fat");
	
	// NOTE: IF you USED the animations and don't need it anymore -> unrequestplayeranimations
	// ATTENTION: You must load at all players the animations, if you force it!
	//unRequestPlayerAnimations(playerid,"amb@smoking_spliff");
	
	if(playerHouseID[playerid] != 0)
	{
	setPlayerDimension(playerid,playerHouseID[playerid]);
	setPlayerCoordinates(playerid, houseCoordSpawnAX[classH[playerid]], houseCoordSpawnAY[classH[playerid]], houseCoordSpawnAZ[classH[playerid]]);	
	displayPlayerText(playerid, 0.3, 0.8, "~y~"+getPlayerName(playerid)+" Home", 5000);
	}
	else if(playerHouseID[playerid] == 0)
	{
	setPlayerDimension(playerid,0);
	setPlayerCoordinates(playerid,2295.821289, 450.136597, 21.830723);
	}
	
	if(pMoney[playerid] != getPlayerMoney(playerid))
	{
	setPlayerMoney(playerid,pMoney[playerid]);
	}
	
	if(pState[playerid] == 1){pState[playerid] = 0;}
	
	if(getPlayerHealth(playerid) < 10)
	{health[playerid] = 50;}
	setPlayerHealth(playerid,health[playerid]);
	setPlayerModel(playerid,pSkin[playerid]);
	setPlayerClothes(playerid, 3, 3);
}
addEvent("playerSpawn", onSpawn);


function onVehicleDeath(vehicleid)
{
	log("Vehicle Death "+vehicleid);
}
addEvent("vehicleDeath",onVehicleDeath);


function onPlayerCommand(playerid, command)
{
	local cmd = split(command, " ");
	if(cmd[0] == "/piss" && pState[playerid] != 1)
	{
		forcePlayerPlayAnimation(playerid,"missttkill","piss_loop");
		return 1;
	}
	else if(cmd[0] == "/sit" && pState[playerid] != 1)
	{
		if(isPlayerOnFoot(playerid) && plaleySit[playerid] != 1)
		{
		forcePlayerPlayAnimation(playerid,"missambtv","sit_down");
		timerSit[playerid] = timer(anim, 1000, -1,playerid);
		plaleySit[playerid] = 1;
		return 1;
		}
	}
	else if(cmd[0] == "/standup" && pState[playerid] != 1)
	{
		if(plaleySit[playerid] == 1)
		{
			if(timerSit[playerid].isActive())
			{
				timerSit[playerid].kill();
				plaleySit[playerid] = 0;
			}
		}
		return 1; 
	}
	else if(cmd[0] == "/dim")
	{
	if(cmd.len() != 2){return 1;}
	setPlayerDimension(playerid, cmd[1].tointeger());
	return 1;
	}
	else if(cmd[0] == "/angle")
	{
		setPlayerHeading(playerid,cmd[1].tointeger());
		return 1;
	}
	else if(cmd[0] == "/getdim")
	{
		sendPlayerMessage(playerid,"VirtualWorldID: "+getPlayerDimension(playerid));
		return 1;
	}
	else if(cmd[0] == "/gethealth")
	{
		sendPlayerMessage(playerid,"Здоровье: "+getPlayerHealth(playerid)+"/100");
		return 1;
	}
	else if(cmd[0] == "/time" && pState[playerid] != 1)
	{

		setPlayerUseMobilePhone(playerid,true);
		if(currTime.hour < 10 && currTime.min < 10)
		{
		sendPlayerMessage(playerid,"Время: 0"+currTime.hour+":0"+currTime.min);
		}
		else if(currTime.hour < 10 && currTime.min > 9)
		{
		sendPlayerMessage(playerid,"Время: 0"+currTime.hour+":"+currTime.min);
		}
		else if(currTime.hour > 9 && currTime.min < 10)
		{
		sendPlayerMessage(playerid,"Время: "+currTime.hour+":0"+currTime.min);
		}
		else {
		sendPlayerMessage(playerid,"Время: "+currTime.hour+":"+currTime.min);
		}
		timer(timeView,1000,1,playerid);
		return 1;
	}
	else if(cmd[0] == "/buyhouse")
	{
	if(getPlayerDimension(playerid) == 0){sendPlayerMessage(playerid,"Вы не в доме!");return 1;}
	
		if(playerHouseID[playerid] == 0 && selledHouse[getPlayerDimension(playerid)] == 1)
		{	
			if(pMoney[playerid] >= 2000000)
			{
				pMoney[playerid] -= 2000000;
				playerHouseID[playerid] = getPlayerDimension(playerid);
				selledHouse[playerHouseID[playerid]] = 0;
				setPlayerMoney(playerid,pMoney[playerid]);
				////////////////////////////////////////////////////
				setBlipColor(blipsHouses[playerHouseID[playerid]-1],0x0000FFFF,-1); // Имеется владелец
				houseInfoPName[playerHouseID[playerid]] = getPlayerName(playerid);
				setBlipName(blipsHouses[playerHouseID[playerid]-1], houseInfoPName[playerHouseID[playerid]]);
				////////////////////////////////////////////////////
				local ini = EasyINI(getPlayerName(playerid)+".ini");
				ini.setKey("stats","money",pMoney[playerid].tointeger());
				ini.setKey("stats","houseClass",1);
				ini.setKey("stats","houseNumber",playerHouseID[playerid]);
				ini.saveData();
				if(carID[playerid] != 300)
				{
				playerVehicleHouse[playerHouseID[playerid]] = createVehicleEx(carID[playerid], vehiclePosClassAX[playerHouseID[playerid]], vehiclePosClassAY[playerHouseID[playerid]], vehiclePosClassAZ[playerHouseID[playerid]], vehicleRotClassAX[playerHouseID[playerid]], vehicleRotClassAY[playerHouseID[playerid]], vehicleRotClassAZ[playerHouseID[playerid]], 1, 1, 1, 1);
				setVehicleDimension(playerVehicleHouse[playerHouseID[playerid]],0);
				setVehicleLocked(playerVehicleHouse[playerHouseID[playerid]],1);
				sendPlayerMessage(playerid,"Поздравляем вас с покупкой дома! Ваша машина припаркована рядом.");
				}
				else
				{
				sendPlayerMessage(playerid,"Поздравляем вас с покупкой дома!");
				}
				saveHouseInfo(playerid); // Сохраняет имя и номер дома, а так-же, инфу продан или нет
			}
			else
			{
			sendPlayerMessage(playerid,"У вас нет столько денег!");
			return 1;
			}
			
		}
		else if(selledHouse[getPlayerDimension(playerid)] == 1 && playerHouseID[playerid] != 0)
		{
			sendPlayerMessage(playerid,"У вас уже есть дом.");
		}
		return 1;
	}
	else if(cmd[0] == "/fixcar")
	{
		if(playerHouseID[playerid] != 0 && playerVehicleHouse[playerHouseID[playerid]] != 300)
		{
			if(pMoney[playerid] >= 5000)
			{
				deleteVehicle(playerVehicleHouse[playerHouseID[playerid]]);
				playerVehicleHouse[playerHouseID[playerid]] = createVehicleEx(carID[playerid], vehiclePosClassAX[playerHouseID[playerid]], vehiclePosClassAY[playerHouseID[playerid]], vehiclePosClassAZ[playerHouseID[playerid]], vehicleRotClassAX[playerHouseID[playerid]], vehicleRotClassAY[playerHouseID[playerid]], vehicleRotClassAZ[playerHouseID[playerid]], 1, 1, 1, 1);			
				setVehicleHealth(playerVehicleHouse[playerHouseID[playerid]],1000);
				pVehicleHealth[playerid] = 1000;
				setVehicleLocked(playerVehicleHouse[playerHouseID[playerid]],pVehicleLocked[playerid]);
				pMoney[playerid] -= 5000;
				setPlayerMoney(playerid,pMoney[playerid]);
				local ini = EasyINI(getPlayerName(playerid)+".ini");
				ini.setKey("stats","money",pMoney[playerid]);
				ini.saveData();
			}
		}
		return 1;
	}
	else if(cmd[0] == "/umb" && pState[playerid] != 1)
	{
		forcePlayerPlayAnimation(playerid,"amb@umbrella_f_fat","umbrella_idle_hold_walk");
		return 1;
	}
	else if(cmd[0] == "/tel")
	{
		setPlayerCoordinates(playerid,-162.3023,592.3933,118.7903); // Квартира А класса полюбому! -Выход на крышу
		return 1;
	}
	else if(cmd[0] == "/tel1")
	{
		setPlayerCoordinates(playerid,854.0030,-518.7424,16.2905); // Обычная квартира, 2 двери
		return 1;
	}
	else if(cmd[0] == "/tel2")
	{
		setPlayerCoordinates(playerid,1378.6427,526.4754,33.1302); // Обычная разьебаная квартира, есть выход на крышу, 1 дверь входа
		return 1;
	}
	else if(cmd[0] == "/tel3")
	{
		setPlayerCoordinates(playerid,-547.8577,1246.4367,97.5397); // прикольная квартира, 1 вход, немного мусора есть внутри
		return 1;
	}
	else if(cmd[0] == "/tel4")
	{
		setPlayerCoordinates(playerid,-128.4903,1498.5248,22.7824); // квартира, лучше предыдущей, 1 вход.
		return 1;
	}
	else if(cmd[0] == "/tel5")
	{
		setPlayerCoordinates(playerid,-1003.3589,1223.5002,28.4332); // Самая галимая квартира, 1 вход
		return 1;
	}
	else if(cmd[0] == "/tel6")
	{
		setPlayerCoordinates(playerid,1371.2750,206.8270,35.6886); // Дерьмо..
		return 1;
	}
	else if(cmd[0] == "/tel7")
	{
		setPlayerCoordinates(playerid,-123.7611,1513.9210,22.7825); // Бомжарня..
		return 1;
	}
	else if(cmd[0] == "/tel8")
	{
		setPlayerCoordinates(playerid,564.7722,1391.2448,30.8600); // Квартира без ничего, немного отстойно, 1 вход
		return 1;
	}
	else if(cmd[0] == "/tel9")
	{
		setPlayerCoordinates(playerid,-131.9487,1379.2197,32.8019); // Маленькая уютная квартира, нету входа, есть окна с которых можно выпрыгнуть.
		return 1;
	}
	else if(cmd[0] == "/payday")
	{
		return payDay();
	}
	if(cmd[0] == "/clothes")
	{
		setPlayerClothes(playerid, cmd[1].tointeger(), cmd[2].tointeger());
	}
	if(cmd[0] == "/attachobjecttoped")
	{
		attachObjectToPlayer(playerid,cmd[1].tointeger(),0.5,0.3,0.5,0.0,90.0,0.0);
	}
	if(cmd[0] == "/attachobjecttopedbone")
	{
		attachObjectToPlayerBone(playerid,cmd[1].tointeger(),0.5,0.3,0.5,0.0,90.0,0.0,cmd[2].tointeger());
	}
	if(cmd[0] == "/attachobjecttovehicle")
	{
		attachObjectToVehicle(cmd[1].tointeger(),cmd[2].tointeger(),0.0,0.0,1.0,0.0,0.0,0.0);
	}
	if(cmd[0] == "/detachobject")
	{
		detachObject(cmd[1].tointeger());
	}
	if(cmd[0] == "/createobject")
	{
		local pos = getPlayerCoordinates(playerid);
		local object = createObject(cmd[1].tointeger(), pos[0]+2.0, pos[1]+2.0, pos[2], 0.0, 0.0, 0.0);
		sendPlayerMessage(playerid, "Object: "+object, 0xFFFFFFAA);
	}
	if(cmd[0] == "/moveobject")
	{
	local pos = getPlayerCoordinates(playerid);
		moveObject(cmd[1].tointeger(), pos[0], pos[1]+0.5, pos[2], 1000.0, 0,0,0);
	local posObj = getObjectCoordinates(cmd[1].tointeger());
	sendPlayerMessage(playerid, "ObjectX: "+posObj[0]+" Y:"+posObj[1]+" Z:"+posObj[2], 0xFFFFFFAA);
	}
	if(cmd[0] == "/moveobjectrot")
	{
		moveObject(cmd[1].tointeger(), 1727.337769, 705.455688, 25.831680, 5000.0, 0, 0, 0);
	}
	if(cmd[0] == "/rotateobject")
	{
		rotateObject(cmd[1].tointeger(), 0, 0, 0, 5000.0);
	}
	if(cmd[0] == "/sayspeech")
	{
		sayPlayerSpeech(playerid,"JIMMY_PEGORINO", "GET_OUT_OF_HERE");
		return 1;
	}
	if(cmd[0] == "/alarm")
	{
		setVehicleAlarm(getPlayerVehicleId(playerid),cmd[1].tointeger());
	}
	if(cmd[0] == "/mobilephone")
	{
		if(cmd[1].tointeger() == 1)
			setPlayerUseMobilePhone(playerid,true);
		else if(cmd[1].tointeger() == 0)
			setPlayerUseMobilePhone(playerid,false);
	}
	if(cmd[0] == "/displayHudMessage")
	{
		displayHudNotification(playerid,1,"UNREAD_MESSAGES");
	}
	if(cmd[0] == "/variation")
	{
		setVehicleVariation(getPlayerVehicleId(playerid),cmd[1].tointeger());
	}
	if(cmd[0] == "/attachcameratovehicle")
	{
		attachPlayerCameraToVehicle(playerid,cmd[1].tointeger());
	}
	if(cmd[0] == "/attachcameratoplayer")
	{
		attachPlayerCameraToPlayer(playerid,cmd[1].tointeger());
	}
	if(cmd[0] == "/name")
	{
		sendPlayerMessage(playerid,"VEHILCENAME:"+getVehicleName(getVehicleModel(getPlayerVehicleId(playerid))));
	}
	if(cmd[0] == "/fadein")
	{
		fadePlayerScreenIn(playerid,5);
	}
	if(cmd[0] == "/fadeout")
	{
		fadePlayerScreenOut(playerid, 5);
	}
	if(cmd[0] == "/policereport")
	{
		triggerPlayerPoliceReport(playerid,"SCRIPTED_REPORTS_C4");
	}
	if(cmd[0] == "/mission")
	{
		triggerPlayerMissionSound(playerid,6);
	}
	if(cmd[0] == "/sound")
	{
		triggerPlayerGameSound(playerid,"MOBILE_PHONE_SMS_RECIEVE");
	}
	if(cmd[0] == "/forcetaxi1")
	{
		forcePlayerPlayAnimation(playerid,"amb@taxi_wait_i_f_b","look_around");
	}
	if(cmd[0] == "/forcetaxi2")
	{
		forcePlayerPlayAnimation(playerid,"amb@taxi_hail_f","hail_right");
	}
	if(cmd[0] == "/taxi")
	{
		setVehicleTaxiLights(getPlayerVehicleId(playerid),true);
	}
	if(cmd[0] == "/taxioff")
	{
		setVehicleTaxiLights(getPlayerVehicleId(playerid),false);
	}
	if(cmd[0] == "/createActor")
	{
		local pos = getPlayerCoordinates(playerid);
		local actor = createActor(8,pos[0],pos[1],pos[2],90.0);
		toggleActorHelmet(actor,false);
		toggleActorFrozen(actor,false);
		setActorName(actor,"JeNkStAX");
		toggleActorNametag(actor,true);
		forceAnimationAtActor(actor,"amb@smoking_spliff","create_spliff");
		
		//
		local actorcount = getActorCount();
		sendPlayerMessage(playerid,"Actorcount: "+actorcount,0xFFFFFFAA);
	}
	if(cmd[0] == "/toghelmet1")
	{
		toggleActorHelmet(0,true);
	}
	if(cmd[0] == "/toghelmet2")
	{
		toggleActorHelmet(0,false);
	}
	if(cmd[0] == "/togfrozen1")
	{
		toggleActorFrozen(0,true);
	}
	if(cmd[0] == "/togfrozen2")
	{
		toggleActorFrozen(0,false);
	}
	if(cmd[0] == "/walk")
	{
		actorWalkToCoordinatesForPlayer(playerid,0,0.0,0.0,0.0,1);
	}
	if(cmd[0] == "/setname")
	{
		setActorName(0,"Fred");
	}
	if(cmd[0] == "/togname1")
	{
		toggleActorNametag(0,true);
	}
	if(cmd[0] == "/togname2")
	{
		toggleActorNametag(0,false);
	}
	if(cmd[0] == "/forceanim")
	{
		forceActorAnimation(0,"hello", "gestures@niko");
	}
	if(cmd[0] == "/grav")
	{
		if(cmd.len() == 2)
		{
		setPlayerGravity(playerid, cmd[1].tointeger());
		}
		return 1;
	}
	
	if(cmd[0] == "/givehelm")
	{
		givePlayerHelmet(playerid);
		return 1;
	}
	
	if(cmd[0] == "/removehelm")
	{
		removePlayerHelmet(playerid);
		return 1;
	}
	
	if(cmd[0] == "/kill")
	{
		setPlayerHealth(playerid, -1);
		return 1;
	}
	
	if(cmd[0] == "/model")
	{
		if(cmd.len() == 2)
		{
			if(setPlayerModel(playerid, cmd[1].tointeger()))
				sendPlayerMessage(playerid, "Model set to " + cmd[1], White);
		}

		return 1;
	}

	if(cmd[0] == "/wep")
	{
		if(cmd.len() == 3)
			givePlayerWeapon(playerid, cmd[1].tointeger(), cmd[2].tointeger());

		return 1;
	}

	if(cmd[0] == "/h" || cmd[0] == "/health")
	{
		if(cmd.len() == 2)
		{
			if(cmd[1].tofloat() >= 0 && cmd[1].tofloat() <= 200)
				setPlayerHealth(playerid, cmd[1].tointeger());
		}

		return 1;
	}

	if(cmd[0] == "/a" || cmd[0] == "/armour")
	{
		if(cmd.len() == 2)
		{
			if(cmd[1].tofloat() > 0 && cmd[1].tofloat() <= 200)
			{
				sendPlayerMessage(playerid, "Armour change to " + cmd[1]);
				setPlayerArmour(playerid, cmd[1].tointeger());
			}
		}

		return 1;
	}

	if(cmd[0] == "/autoaim")
	{
		if(cmd.len() == 2)
		{
			if(cmd[1] == "true") togglePlayerAutoAim(playerid, true);
			else togglePlayerAutoAim(playerid, false);
		}

		return 1;
	}

	if(cmd[0] == "/v")
	{
		if(cmd.len() == 2)
		{
			local model = cmd[1].tointeger();
			local pos;
			if(isPlayerInAnyVehicle(playerid))
				pos = getVehicleCoordinates(getPlayerVehicleId(playerid));
			else
				pos = getPlayerCoordinates(playerid);
			local heading = getPlayerHeading(playerid);
			local veh = createVehicleEx(model, pos[0], pos[1], pos[2], 0.0, 0.0, heading, 1, 1, 1, 1);
			if(veh != INVALID_VEHICLE_ID)
			{
				warpPlayerIntoVehicle(playerid, veh);
				sendPlayerMessage(playerid, getVehicleName(model) + " spawned at your position (ID " + veh + ").");
			}
		}
		else if(cmd.len() == 6)
		{
			local model = cmd[1].tointeger();
			local pos;
			if(isPlayerInAnyVehicle(playerid))
				pos = getVehicleCoordinates(getPlayerVehicleId(playerid));
			else
				pos = getPlayerCoordinates(playerid);
			local heading = getPlayerHeading(playerid);
			local veh = createVehicleEx(model, pos[0], pos[1], pos[2], 0.0, 0.0, heading, cmd[2].tointeger(),cmd[3].tointeger(),cmd[4].tointeger(),cmd[5].tointeger());
			if(veh != INVALID_VEHICLE_ID)
			{
				warpPlayerIntoVehicle(playerid, veh);
				sendPlayerMessage(playerid, getVehicleName(model) + " spawned at your position (ID " + veh + ").");
			}
		}

		return 1;
	}

	if(cmd[0] == "/delveh")
	{
		if(isPlayerInAnyVehicle(playerid))
		{
			local vehicleId = getPlayerVehicleId(playerid);
			deleteVehicle(vehicleId);
			log("VehDel");
			//sendPlayerMessage(playerid, "Your vehicle has been deleted.");
		}
		else
		{
			sendPlayerMessage(playerid, "You are not in a vehicle.");
		}

		return 1;
	}
	
	if(cmd[0] == "/out")
	{
		sendPlayerMessage(playerid, "You are being warped out of your vehicle.");
		removePlayerFromVehicle(playerid);
		return 1;
	}

	if(cmd[0] == "/out2")
	{
		sendPlayerMessage(playerid, "You are leaving your vehicle.");
		removePlayerFromVehicle(playerid, true);
		return 1;
	}

	if(cmd[0] == "/money")
	{
		if(cmd.len() == 2)
		{
			setPlayerMoney(playerid, cmd[1].tointeger());
			pMoney[playerid] = cmd[1].tointeger();
			sendPlayerMessage(playerid, "Money set", White);
		}

		return 1;
	}
	
	if(cmd[0] == "/infotext")
	{
		if(cmd.len() == 3)
			displayPlayerInfoText(playerid, cmd[1].tostring(), cmd[2].tointeger());

		return 1;
	}

	if(cmd[0] == "/texttoall")
	{
		if(cmd.len() == 3)
			displayTextToAll(0.1, 0.1, cmd[1].tostring(), cmd[2].tointeger());

		return 1;
	}

	if(cmd[0] == "/physics")
	{
		if(cmd.len() == 2)
			togglePlayerPhysics(playerid, cmd[1].tointeger());

		return 1;
	}

	if(cmd[0] == "/controls")
	{
		if(cmd.len() == 2)
			togglePlayerControls(playerid, cmd[1].tointeger());

		return 1;
	}

	if(cmd[0] == "/wanted")
	{
		if(cmd.len() == 2)
			setPlayerWantedLevel(playerid, cmd[1].tointeger());
		
		return 1;
	}

	if(cmd[0] == "/getrot")
	{
		if(isPlayerInAnyVehicle(playerid))
		{
			local rot = getVehicleRotation(getPlayerVehicleId(playerid));
			sendPlayerMessage(playerid, "Rot(X: " + rot[0] + ", Y: " + rot[1] + ", Z: " + rot[2] + ")");
		}
	}

	if(cmd[0] == "/setrot")
	{
		if(cmd.len() == 4)
		{
			if(isPlayerInAnyVehicle(playerid))
			{
				setVehicleRotation(getPlayerVehicleId(playerid), cmd[1].tofloat(), cmd[2].tofloat(), cmd[3].tofloat());
				sendPlayerMessage(playerid, "Rotation set");
			}
		}
	}
	
	if(cmd[0] == "/anim")
	{
		forcePlayerPlayAnimation(playerid,"amb@argue","angryman");
	}

	if(cmd[0] == "/ind")
	{
		if(cmd.len() == 3)
		{
			if(isPlayerInAnyVehicle(playerid))
			{
				local index = cmd[1].tointeger();

				if(index < 0 || index > 3)
				{
					sendPlayerMessage(playerid, "Invalid indicator index.");
				}
				else
				{
					local vehicle = getPlayerVehicleId(playerid);
					local indicators = getVehicleIndicators(vehicle);
					local toggle = ((cmd[2].tointeger() == 1) ? true : false);
					indicators[index] = toggle;
					setVehicleIndicators(vehicle, indicators[0], indicators[1], indicators[2], indicators[3]);
					sendPlayerMessage(playerid, "Indicator index " + index + " set to " + toggle + ".");
				}
			}
		}
	}

return 1;
}
addEvent("playerCommand", onPlayerCommand);

function onPlayerDeath(playerid, killerid, killerweapon, killervehicle)
{
	return 1;
}
addEvent("playerDeath", onPlayerDeath);

function onWebRequest(uri, remote_ip, remote_method)
{
	loging(format("Web request: %s [%s] [%s]", uri, remote_ip, remote_method));
}
addEvent("webRequest", onWebRequest);

function onVehicleDamage(vehicleid,oldhealth,oldpetrol,newhealth,newpetrol)
{
	//loging(format("VEHICLE DAMAGE: %d, %d, %d, %d, %d",vehicleid,oldhealth,oldpetrol,newhealth,newpetrol));
}
addEvent("vehicleDamage",onVehicleDamage);

function onPlayerShot(playerid,x,y,z,xl,yl,zl,shot)
{
/*
	if(shot)
		loging(format("WEP: %d SHOT(%f, %f, %f)|LOOKAT(%f, %f, %f)",playerid,x,y,z,xl,yl,zl));
	else
		loging(format("WEP: %d AIM(%f, %f, %f)|LOOKAT(%f, %f, %f)",playerid,x,y,z,xl,yl,zl));
*/
return 1;
}
addEvent("playerShot",onPlayerShot);

function onHeadMovement(playerid, oldx, oldy, oldz, newx, newy, newz)
{
	//loging(format("HEAD: %d OLD(%f, %f, %f) | NEW (%f, %f, %f)",playerid,oldx,oldy,oldz,newx,newy,newz));
}
addEvent("headMove",onHeadMovement);

function onLightsRequest(playerid)
{
	if(!isPlayerInAnyVehicle(playerid) || getPlayerSeatId(playerid) != 0){return 1;}
	local veh = getPlayerVehicleId(playerid);
	setVehicleLights(veh,!getVehicleLights(veh));
}
addEvent("lights",onLightsRequest);

function onLockVehicleRequest(playerid)
{
	if(playerVehicleHouse[playerHouseID[playerid]] != 300)
	{
		local locked = 0;
		if(getVehicleLocked(playerVehicleHouse[playerHouseID[playerid]])){
		displayPlayerText(playerid, 0.3, 0.8, "~y~Unlocked", 2000);
		locked = 0;
		}else{
		displayPlayerText(playerid, 0.3, 0.8, "~y~Locked", 2000);
		locked = 1;
		}
		setVehicleLocked(playerVehicleHouse[playerHouseID[playerid]],locked);
		pVehicleLocked[playerid] = locked;
	}
return 1;
}
addEvent("unlock",onLockVehicleRequest);

function onVehicleRequest(playerid,vehicleid,seat)
{
	if(plaleySit[playerid] == 1)
	{
		if(timerSit[playerid].isActive()) // Kill timer sit animation
		{
			timerSit[playerid].kill();
			plaleySit[playerid] = 0;
		}
	}
	return 1;
}
addEvent("vehicleEntryRequest", onVehicleRequest);

function onSwitchEngine(playerid)
{
	if(!isPlayerOnFoot(playerid) && getPlayerSeatId(playerid) == 0)
	{
		if(vehicleFuel[getPlayerVehicleId(playerid)] > 0.0)
		{
			local enginestate = getVehicleEngineState(getPlayerVehicleId(playerid));
			setVehicleEngineState(getPlayerVehicleId(playerid),!enginestate);
		}
		else
		{
			sendPlayerMessage(playerid,"В машине нет бензина, сходите на заправку и купитье [FF0000FF]Канистру.", 0xFFFFFFFF,true);
		}
	}
}		
addEvent("switchEngine", onSwitchEngine);

function onVehicleEntryComplete(playerid, vehicleid, seatid)
{
	if(seatid == 0)
	{
		if(!getVehicleEngineState(vehicleid))
		{
		sendPlayerMessage(playerid,"Нажмите [FF0000FF]Y [FFFFFFFF]чтобы завести или заглушить двигатель. ",0xFFFFFFFF, true);
		}
	}
	
	if(seatid < 1) // В этой функции баг, таймер всеравно запускается
	{
		timerSpeed[playerid] = timer(vStats,500,-1,playerid);
	}
	
}
addEvent("vehicleEntryComplete", onVehicleEntryComplete);

function onDialogResponse(playerid, GUIDIalogId, response, guiBtnChoosen, strBtn)
{
togglePlayerControls(playerid, true);

if(GUIDIalogId == 0 && response == 0){kickPlayer(playerid, true);return 1;} // Кикаем того кто не хочет регистрироваться
if(GUIDIalogId == 1 && response == 0){kickPlayer(playerid, true);return 1;} // Если передумал логиниться
if(GUIDIalogId == 2 && response == 0){kickPlayer(playerid, true);return 1;} // Если отказался выбрать скин
if(GUIDIalogId == 5 && response == 0){dialog.showPlayerDialog(playerid,4,2,"Приём на работу:","Танцовщица в стриптиз клуб");return 1;}
if(GUIDIalogId == 1001 && response == 0 || GUIDIalogId == 1002 && response == 0 || GUIDIalogId == 1001 && response == 1){dialog.showPlayerDialog(playerid,1000,2,"Банковские услуги:","Посмотреть счет\nСнять деньги");return 1;} // Возврат в главное меню

	if(response)
	{
		switch(GUIDIalogId)
		{
			case 0: // Регистрация
			{
				if(strBtn == "wrong")
				{
					dialog.showPlayerDialog(playerid,0,1,"Регистрация, введите пароль:",""); // 0 = id диалога
					sendPlayerMessage(playerid,"Пароль должен быть не меньше 6 и не больше 14 символов!");
					return 1;
				}
				/////////////////////////////////////////////////////
				local iniBank = EasyINI("bankConfig.ini");
				iniBank.setKey("bankCheck",getPlayerName(playerid),0);
				iniBank.setKey("playerCheck",getPlayerName(playerid),0);
				iniBank.saveData();
				/////////////////////////////////////////////////////
				local ini = EasyINI(getPlayerName(playerid)+".ini");
				ini.setKey("stats","pwd",strBtn);
				ini.setKey("stats","health",100);
				ini.setKey("stats","houseNumber",0);
				ini.setKey("stats","houseClass",0);
				ini.setKey("stats","vehicle",300);
				ini.setKey("stats","vehicleHealth",1000);
				ini.setKey("stats","money",0);
				ini.setKey("stats","vehicleFuel",120.0);
				ini.setKey("stats","pSkin",0);
				ini.setKey("stats","pVehicleLocked",1);
				ini.setKey("stats","pWork",0);
				ini.saveData();
				setPlayerModel(playerid,122);
				dialog.showPlayerDialog(playerid,3,2,"Какого вы пола?:","Мужчина\nЖенщина\nПродолжить");
			}
			break;
			case 1: // Вход
			{
				local ini = EasyINI(getPlayerName(playerid)+".ini");
				local tmpPwd = ini.getKey("stats","pwd");
				if(tmpPwd == strBtn)
				{
					// Загружаем данные игрока
					health[playerid] = ini.getKey("stats","health").tointeger();
					pMoney[playerid] = ini.getKey("stats","money").tointeger();
					pWork[playerid] = ini.getKey("stats","pWork").tointeger();
					pVehicleHealth[playerid] = ini.getKey("stats","vehicleHealth").tointeger();
					pSkin[playerid] = ini.getKey("stats","pSkin").tointeger();
					setPlayerModel(playerid,pSkin[playerid]);
					pVehicleLocked[playerid] = ini.getKey("stats","pVehicleLocked").tointeger();
					pGender[playerid] = ini.getKey("stats","pGender").tointeger();
					setPlayerMoney(playerid,pMoney[playerid]);
					if(health[playerid] < 5)
					{
					health[playerid] = 10;
					}
					setPlayerHealth(playerid,health[playerid]);
					playerHouseID[playerid] = ini.getKey("stats","houseNumber").tointeger();
					if(playerHouseID[playerid] != 0){selledHouse[playerHouseID[playerid]] = 0;}
					carID[playerid] = ini.getKey("stats","vehicle").tointeger();
					playerVehicleHouse[playerHouseID[playerid]] = 300;
					if(playerHouseID[playerid] != 0)
					{
					classH[playerid] = ini.getKey("stats","houseClass").tointeger();
					
					setPlayerDimension(playerid,playerHouseID[playerid]);
					setPlayerCoordinates(playerid, houseCoordSpawnAX[classH[playerid]], houseCoordSpawnAY[classH[playerid]], houseCoordSpawnAZ[classH[playerid]]);	
					displayPlayerText(playerid, 0.3, 0.8, "~y~"+getPlayerName(playerid)+" Home"/*houseClassANames[houseID[playerHouseID[playerid]]]*/, 5000);
					}
					if(carID[playerid] != 300)
					{
						playerVehicleHouse[playerHouseID[playerid]] = createVehicleEx(carID[playerid], vehiclePosClassAX[playerHouseID[playerid]], vehiclePosClassAY[playerHouseID[playerid]], vehiclePosClassAZ[playerHouseID[playerid]], vehicleRotClassAX[playerHouseID[playerid]], vehicleRotClassAY[playerHouseID[playerid]], vehicleRotClassAZ[playerHouseID[playerid]], 1, 1, 1, 1);
						
						setVehicleHealth(playerVehicleHouse[playerHouseID[playerid]],pVehicleHealth[playerid]);
						
						setVehicleLocked(playerVehicleHouse[playerHouseID[playerid]],pVehicleLocked[playerid]);

						vehicleFuel[playerVehicleHouse[playerHouseID[playerid]]] = ini.getKey("stats","vehicleFuel").tofloat();
					}
					registredUser[playerid] = 2; // Залогинился
				}
				else
				{
					// Что-то не так, просим снова сделать вход
					dialog.showPlayerDialog(playerid,1,1,"Вход:",""); // 0 = id диалога
				}
				ini.saveData();
			}
			break;
			case 2:
			{
				if(pGender[playerid] == 1) // Мужики!
				{
					if(guiBtnChoosen == 0)
					{
					pSkin[playerid] += 1;
					if(pSkin[playerid] > 3){pSkin[playerid] = 0;}
						setPlayerModel(playerid,skinsHobosMale[pSkin[playerid]]);
						dialog.showPlayerDialog(playerid,2,2,"Кто вы?:","Далее\nНазад\nСохранить");
					}
					else if(guiBtnChoosen == 1)
					{
					pSkin[playerid] -= 1;
						if(pSkin[playerid] < 0){pSkin[playerid] = 3;}
						setPlayerModel(playerid,skinsHobosMale[pSkin[playerid]]);
						dialog.showPlayerDialog(playerid,2,2,"Кто вы?:","Далее\nНазад\nСохранить");
					}
					else if(guiBtnChoosen == 2)
					{
					// Save
					local iniTmp = EasyINI(getPlayerName(playerid)+".ini");
					iniTmp.setKey("stats","pSkin",getPlayerModel(playerid).tointeger());
					iniTmp.setKey("stats","pGender",pGender[playerid].tointeger());
					iniTmp.saveData();
					dialog.showPlayerDialog(playerid,1,1,"Вход:",""); // 0 = id диалога
					}
				}
				
				sendPlayerMessage(playerid,"Choosen: "+guiBtnChoosen+" str: "+strBtn);
			}
			break;
			case 3: // Gender choose
			{
				if(guiBtnChoosen == 0)
				{// Man
					pGender[playerid] = 1;
					dialog.showPlayerDialog(playerid,2,2,"Кто вы?:","Далее\nНазад\nСохранить");
				}
				else if(guiBtnChoosen == 1)
				{// woman
					pGender[playerid] = 0;
					dialog.showPlayerDialog(playerid,2,2,"Кто вы?:","Далее\nНазад\nСохранить");
				}
				else if(guiBtnChoosen == 2)
				{// Next stap
					dialog.showPlayerDialog(playerid,2,2,"Кто вы?:","Далее\nНазад\nСохранить");
				}
				
			}
			break;
			case 4:
			{
				// Информация о работе
				if(guiBtnChoosen == 0)
				{
					dialog.showPlayerDialog(playerid,5,0,"Информация о работе:","Танцуйте и зарабатывайте деньги, деньги будут начислятся\nза каждый танец на ваш личный счёт в банке.\nЧтобы начать танцевать и зарабатывать деньги, станте\nна Чек-Пойнт в Стрип-Клубе.");
				}
			}
			break;
			case 5:
			{
				// Решение
				dialog.showPlayerDialog(playerid,6,2,"Желаете работат?:","Устроиться\nЯ ещё подумаю");
			}
			break;
			case 6:
			{
				if(guiBtnChoosen == 0) // Устроиться
				{
					// Принять на работу
					if(pWork[playerid] == 0)
					{
						if(pGender[playerid] == 0)
						{
							pWork[playerid] = 1; // Танцовщица в стрип клубе
							local ini = EasyINI(getPlayerName(playerid)+".ini");
							ini.setKey("stats","pWork",pWork[playerid]);
							ini.saveData();
							sendPlayerMessage(playerid,"[FFFFFFFF]<Сервер> Вас успешно принято на работу [FF0000FF]Танцовщица Стриптиза",0xFFFFFFFF,true);
							sendPlayerMessage(playerid,"[FFFFFFFF]<Сервер> Нажмите [FF0000FF]J [FFFFFFFF]чтобы получить доп. информацию.",0xFFFFFFFF,true);
							
						}
						else
						{
							sendPlayerMessage(playerid,"[FFFFFFFF]<Сервер> [FF0000FF]Вы не Женщина, эта работа только для женщин.",0xFF0000FF,true);
						}
					}
					else
					{
						sendPlayerMessage(playerid,"[FFFFFFFF]<Сервер> [FF0000FF]Вы уже имеете работу, сначала увольтесь.",0xFF0000FF,true);
					}
				}
				else if(guiBtnChoosen == 1) // Я ещё подумаю
				{
					// К списку работ
					dialog.showPlayerDialog(playerid,4,2,"Приём на работу:","Танцовщица в стриптиз клуб");
				}
			}
			break;
			
			
			case 1000:
			{
			local payIni = EasyINI("bankConfig.ini");
			local mTmp = payIni.getKey("playerCheck",getPlayerName(playerid).tostring()).tointeger();
			
				if(guiBtnChoosen == 0)
				{
					dialog.showPlayerDialog(playerid,1001,0,"Чек:",format("На вашем счету: %d"+"$  ",mTmp));
				}
				else if(guiBtnChoosen == 1)
				{
					dialog.showPlayerDialog(playerid,1002,1,format("Снятие наличных: У вас: %d"+"$",mTmp),"Введите сумму:  ");
				}
				
			payIni.saveData();
			}
			break;
			case 1002:
			{
			local payIni = EasyINI("bankConfig.ini");
			local mTmp = payIni.getKey("playerCheck",getPlayerName(playerid).tostring()).tointeger();
			
			if(!isNumbers(strBtn) || strBtn.len() < 1){return dialog.showPlayerDialog(playerid,1002,1,format("Снятие наличных: У вас: %d"+"$",mTmp),"Введите сумму:  ");}
				local moneyL = strBtn.tointeger();
				if(moneyL > mTmp){return 1;}
				mTmp = mTmp - moneyL;
				payIni.setKey("playerCheck",getPlayerName(playerid).tostring(),mTmp);
				payIni.saveData();
				
				local pIni = EasyINI(getPlayerName(playerid)+".ini");
				pMoney[playerid] += moneyL;
				pIni.setKey("stats","money",pMoney[playerid]);
				givePlayerMoney(playerid,moneyL);
				pIni.saveData();
			}
			break;
		}
	}
return 1;
}
addEvent("dialogResponse",onDialogResponse);


// Timer for health
function onHealthCalc()
{
	
	foreach(i, playername in getPlayers())
    {

		if(fileExists(getPlayerName(i)+".ini")==true)
		{
			if(registredUser[i] == 2)
			{
				local ini = EasyINI(getPlayerName(i)+".ini");
				health[i] = getPlayerHealth(i);
				if(health[i] > 100)
				{
				health[i] = 100;
				sendPlayerMessage(i,"[FFFFFFFF]<Анти-чит> [FF0000FF]Вы были кикнуты с сервера, по подозрению в читерстве.",0xFF0000FF,true);
				kickPlayer(i, true);
				}
					health[i] -= 1; // 64
					setPlayerHealth(i,health[i]);

				if(health[i] < 5){sendPlayerMessage(i,"<Сервер> [FF0000FF]У вас сильно ухудшилось здоровье! Покушайте что нибудь.",0xFFFFFFFF,true);}
					if(playerVehicleHouse[playerHouseID[i]] != 300)
					{
						ini.setKey("stats","vehicleFuel",vehicleFuel[playerVehicleHouse[playerHouseID[i]]]); // сохраняем бензин если есть машина
					}
						ini.setKey("stats","money",pMoney[i]);
						ini.setKey("stats","health",health[i].tointeger());
						if(pVehicleHealth[i] != 0)
						{
						ini.setKey("stats","vehicleHealth",pVehicleHealth[i].tointeger());
						}
						else
						{
						ini.setKey("stats","vehicleHealth",150);
						}
					ini.saveData();
			}
		}
    }
	
return 1;
}


function vStats(playerid)
{
	if(isPlayerConnected(playerid))
	{
		if(isPlayerInAnyVehicle(playerid))
		{
			vehicleid = getPlayerVehicleId(playerid);
			vhealth = getVehicleHealth(vehicleid);
			speed = getSpeed(vehicleid).tointeger();
			
			if(vhealth <= 0)
			{
			vhealth = 0;
			}
			
			if(vehicleFuel[vehicleid] > 0.0)
			{
				if(speed > 0 && speed < 80)
				{
					vehicleFuel[vehicleid] -= 0.003;
				}
				else if(speed > 80 && speed < 160)
				{
					vehicleFuel[vehicleid] -= 0.03;
				}
				else if(speed > 160 && speed < 300)
				{
					vehicleFuel[vehicleid] -= 0.05;
				}
				else if(speed > 300)
				{
					sendPlayerMessage(i,"[Анти-чит] [FF0000FF]Вы были кикнуты с сервера, по подозрению в читерстве.",0xFFFFFFFF,true);
					kickPlayer(i,true);
				}
			}
			else
			{
			vehicleFuel[vehicleid] = 0.0;
				if(getVehicleEngineState(getPlayerVehicleId(playerid)))
				{
				setVehicleEngineState(getPlayerVehicleId(playerid),false);
				sendPlayerMessage(playerid,"В машине кончился бензин.",0xFF0000FF,true);
				}
			}
			engineState = getVehicleEngineState(getPlayerVehicleId(playerid));
			if(engineState)
			{
				stateEng = "~g~ON";
			}else{stateEng = "~r~OFF";}
			
			displayPlayerInfoText(playerid, "~y~Engine: "+ stateEng + "~y~ Fuel: ~g~"+ vehicleFuel[vehicleid].tointeger() +"~y~ \nState: ~g~"+ vhealth +"~y~ Speed: ~g~"+ speed +"~y~ KM/H", 1000);
		}
	}
}

function getSpeed(vehicleid)
{
	local velo = getVehicleVelocity(vehicleid);
	return sqrt(pow(velo[0], 2) + pow(velo[1], 2) + pow(velo[2], 2))*5; 
}

function onAnticheatCheck()
{

	foreach(i, playername in getPlayers())
    {
		if(isPlayerConnected(i))
		{
			if(registredUser[i] == 2)
			{
			moneyToCheck = getPlayerMoney(i);
			//pHealthToCheck = getPlayerHealth(i);
			
				if(playerVehicleHouse[playerHouseID[i]] != 300)
				{
				vehHealth = getVehicleHealth(playerVehicleHouse[playerHouseID[i]]);
				vehStatLock = getVehicleLocked(playerVehicleHouse[playerHouseID[i]]);
				
					if(pVehicleHealth[i] <= 0)
					{
						pVehicleHealth[i] = 0;
					}
					else if(pVehicleHealth[i] > 1000)
					{
						pVehicleHealth[i] = 1000;
						setVehicleHealth(playerVehicleHouse[playerHouseID[i]],pVehicleHealth[i]);
						sendPlayerMessage(i,"[Анти-чит] Вы были кикнуты с сервера, по подозрению в читерстве.");
						kickPlayer(i, true);
					}
					
					pVehicleHealth[i] = getVehicleHealth(playerVehicleHouse[playerHouseID[i]]);
				/*
					if(pVehicleHealth[i] <= 0)
					{
						setVehicleHealth(playerVehicleHouse[playerHouseID[i]],0);
						pVehicleHealth[i] = 0;
					}*/
				
					// Проверяем должна ли быть закрыта машина
					if(pVehicleLocked[i] != vehStatLock)
					{
						setVehicleLocked(playerVehicleHouse[playerHouseID[i]],pVehicleLocked[i]);
					}
					pVehicleLocked[i] = getVehicleLocked(playerVehicleHouse[playerHouseID[i]]);
				}
				
				// Проверяем деньги
			/*	if(moneyToCheck != pMoney[i])
				{
					setPlayerMoney(i,pMoney[i]);
					sendPlayerMessage(i,"Обнаружен чит на деньги! пожалуйста не используйте чит-коды.");
				}
				pMoney[i] = getPlayerMoney(i);
			*/
			/* Не работает, getPlayerHealth не успевает вернуть новое значение..
				// Проверяем здоровье
				if(pHealthToCheck < health[i] || pHealthToCheck > health[i])
				{
					setPlayerHealth(i,health[i]);
					sendPlayerMessage(i,"Обнаружен чит на здоровье! пожалуйста не используйте чит-коды.");
				}
				health[i] = getPlayerHealth(i);
			*/
			
				// Проверяем скин
			/*	if(pSkin[i] != getPlayerModel(i))
				{
					setPlayerModel(i,pSkin[i]);
					sendPlayerMessage(i,"Обнаружен чит на скин! пожалуйста не используйте чит-коды.");
				}
				pSkin[i] = getPlayerModel(i);
			*/
				// Проверяем чит на бензин
				if(isPlayerInAnyVehicle(i))
				{
				local car = getPlayerVehicleId(i);
					if(getVehicleEngineState(car))
					{
						if(vehicleFuel[car] <= 0.0)
						{
							setVehicleEngineState(car,false);
						}
					}
				}
			}
		}
	}
	
return 1;
}

function saveBank(playerid = -1,pSum = -1)
{
	if(fileExists("bankConfig.ini")==false)
	{
	EasyINI("bankConfig.ini");
	return saveBank();
	}

	if(playerid != -1)
	{
	local bankIni = EasyINI("bankConfig.ini");
		if(bankIni.keyExists("bankCheck",getPlayerName(playerid).tostring())==false)
		{
			bankIni.setKey("bankCheck",getPlayerName(playerid).tostring(),0);
			bankIni.setKey("playerCheck",getPlayerName(playerid).tostring(),0);
			bankIni.saveData();
			loging("saveBank("+playerid+","+pSum+")");
			return saveBank(playerid,pSum);
		}
		else
		{
			local pBankSum = bankIni.getKey("bankCheck",getPlayerName(playerid).tostring()).tointeger();
			pBankSum += pSum;
			bankIni.setKey("bankCheck",getPlayerName(playerid).tostring(),pBankSum);
			sendPlayerMessage(playerid,"Вы закончили работу, и заработали: [00FF00FF]"+pSum+"$",0xFFA500FF,true);
			
		if(currTime.hour < 10)
		{
		sendPlayerMessage(playerid,"Деньги будут переведены в банк, в [00FF00FF]0"+(currTime.hour+1)+":00",0xFFA500FF,true);
		}
		else if(currTime.hour == 23)
		{
		sendPlayerMessage(playerid,"Деньги будут переведены в банк, в [00FF00FF]00:00",0xFFA500FF,true);
		}
		else
		{
		sendPlayerMessage(playerid,"Деньги будут переведены в банк, в [00FF00FF]"+(currTime.hour+1)+":00",0xFFA500FF,true);
		}
		
		}
	bankIni.saveData();
	loging("saveBank("+playerid+","+pSum+")");
	}

return 1;
}

function payDay()
{
loging("PayDay");

	if(fileExists("bankConfig.ini")==false){return loging("Error: No \"bankConfig.ini\"");}
	
	local iniPay = EasyINI("bankConfig.ini");
	local pNameTmp;
	local pMoneyBankTmp;
	
	foreach(i, playername in getPlayers())
    {
		if(isPlayerConnected(i))
		{
			if(registredUser[i] == 2)
			{
			pNameTmp = getPlayerName(i).tostring();
				if(fileExists(pNameTmp+".ini"))
				{
				pMoneyBankTmp = 0;
				
					pMoneyBankTmp = iniPay.getKey("bankCheck",pNameTmp).tointeger();
					
					sendPlayerMessage(i,"ххх---------------Зарплата---------------ххх",0x778899FF,true);
					sendPlayerMessage(i,"В этом часу вы заработали: [00FF00FF]"+pMoneyBankTmp+"$",0xFAA460FF,true);
					
					pMoneyBankTmp += iniPay.getKey("playerCheck",pNameTmp).tointeger(); // Сумма в банкомате
					local payForComunal = 0;
					switch(classH[i])
					{
						case 0:break;
						case 1:
						{ // A class
						payForComunal = 150;
						pMoneyBankTmp -= payForComunal;
						sendPlayerMessage(i,"Плата за коммунальные услуги: [00FF00FF]"+payForComunal+"$",0xFAA460FF,true);
						}
						break;
						case 2:
						{ // B class
						payForComunal = 125;
						pMoneyBankTmp -= payForComunal;
						sendPlayerMessage(i,"Плата за коммунальные услуги: [00FF00FF]"+payForComunal+"$",0xFAA460FF,true);
						}
						break;
						case 3:
						{ // C class
						payForComunal = 100;
						pMoneyBankTmp -= payForComunal;
						sendPlayerMessage(i,"Плата за коммунальные услуги: [00FF00FF]"+payForComunal+"$",0xFAA460FF,true);
						}
						break;
						case 4:
						{ // D class
						payForComunal = 75;
						pMoneyBankTmp -= payForComunal;
						sendPlayerMessage(i,"Плата за коммунальные услуги: [00FF00FF]"+payForComunal+"$",0xFAA460FF,true);
						}
						break;
						default:break;
					}
					
					sendPlayerMessage(i,"ххх---------------Зарплата---------------ххх",0x778899FF,true);
					
					iniPay.setKey("playerCheck",pNameTmp,pMoneyBankTmp);
					iniPay.setKey("bankCheck",pNameTmp,0);
					
				pMoneyBankTmp = 0;
				}
			}
		}
	}
	
	iniPay.saveData();

return 1;
}

function isNumbers(str)
{
	for(local i = 0; i < str.len(); i++)
	{

		// '0' to '9'
		if(str[i] >= '0' && str[i] <= '9')
			continue;

		// Disallow all other characters
		return false;
	}

	return true;
}
